# -*- coding: utf-8 -*-
# @Time        :2025/3/5 上午10:33
# @Author      :文刀水寿
# @File        : 16_爬虫_urllib_代理.py
"""
 @Description :
"""
import urllib.request

url = 'https://ip.900cha.com/'

headers = {
    'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0",
}

request = urllib.request.Request(url=url, headers=headers)

proxies = {
    'http': '218.87.205.116:21281'
}
handler = urllib.request.ProxyHandler(proxies=proxies)

opener = urllib.request.build_opener(handler)

response = opener.open(request)

content = response.read().decode('utf8')

with open('ip.html', 'w', encoding='utf8') as fp:
    fp.write(content)
